package com.lijian.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lijian.common.easyui.datagrid.EasyuiDataGridResult;
import com.lijian.common.utils.TaotaoResult;
import com.lijian.mapper.TbItemParamMapper;
import com.lijian.pojo.TbItem;
import com.lijian.pojo.TbItemParam;
import com.lijian.pojo.TbItemParamExample;
import com.lijian.pojo.TbItemParamExample.Criteria;
import com.lijian.service.ItemParamService;

/**
 * <p>Title: ItemParamServiceImpl.java</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * @author lijian
 * @date 2017年3月26日下午2:03:28
 * @version 1.0
 */
@Service
public class ItemParamServiceImpl implements ItemParamService {

	@Autowired
	private TbItemParamMapper itemParamMapper;
	/**
	 * <p>Title: getItemParamByCid</p>
	 * <p>Description: </p>
	 * @param cid
	 * @return
	 * @see com.lijian.service.ItemParamService#getItemParamByCid(java.lang.Long)
	 */
	@Override
	public TaotaoResult getItemParamByCid(Long cid) {
		TbItemParamExample example=new TbItemParamExample();
		Criteria criteria=example.createCriteria();
		criteria.andItemCatIdEqualTo(cid);
		java.util.List<TbItemParam>list=itemParamMapper.selectByExampleWithBLOBs(example);
		if(list!=null && list.size()>0){
			return TaotaoResult.ok(list.get(0));
		}
		return TaotaoResult.ok();
	}
	@Override
	public TaotaoResult insertItemParam(long cid, String paramData) {
		TbItemParam record=new TbItemParam();
		record.setCreated(new Date());
		record.setUpdated(new Date());
		record.setParamData(paramData);
		record.setItemCatId(cid);
		itemParamMapper.insert(record);
		return TaotaoResult.ok();
	}
	@Override
	public EasyuiDataGridResult getItemParamList(Integer page, Integer rows) {
		TbItemParamExample example=new TbItemParamExample();
		PageHelper.startPage(page, rows);
		List<TbItemParam> list=itemParamMapper.selectByExample(example);
		PageInfo<TbItemParam> pageInfo=new PageInfo<TbItemParam>(list);
		return new EasyuiDataGridResult(pageInfo.getTotal(), list);
	}

}
